package com.gitee.wsl.compose.animation.transition

import androidx.compose.animation.core.FiniteAnimationSpec
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.spring
import androidx.compose.animation.shrinkOut
import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.IntSize

//收缩动画。该动画会使对象从一个较大的尺寸逐渐收缩到一个较小的尺寸。
@Stable
fun Transition.Out.shrink(
    animationSpec: FiniteAnimationSpec<IntSize> =
        spring(
            stiffness = Spring.StiffnessMediumLow,
            visibilityThreshold = IntSize.VisibilityThreshold
        ),
    expandFrom: Alignment = Alignment.BottomEnd,
    clip: Boolean = true,
    initialSize: (fullSize: IntSize) -> IntSize = { IntSize(0, 0) },
) = shrinkOut(animationSpec,expandFrom,clip,initialSize)

//水平收缩动画。该动画会使对象从一个较短的宽度逐渐收缩到一个较窄的宽度。
@Stable
fun Transition.Out.shrinkHorizontally(
    animationSpec: FiniteAnimationSpec<IntSize> =
        spring(
            stiffness = Spring.StiffnessMediumLow,
            visibilityThreshold = IntSize.VisibilityThreshold
        ),
    shrinkTowards: Alignment.Horizontal = Alignment.End,
    clip: Boolean = true,
    targetWidth: (fullWidth: Int) -> Int = { 0 }
) = androidx.compose.animation.shrinkHorizontally(animationSpec, shrinkTowards, clip, targetWidth)

//垂直收缩动画。该动画会使对象从一个较高的高度逐渐收缩到一个较短的高度。
@Stable
fun Transition.Out.shrinkVertically(
    animationSpec: FiniteAnimationSpec<IntSize> =
        spring(
            stiffness = Spring.StiffnessMediumLow,
            visibilityThreshold = IntSize.VisibilityThreshold
        ),
    shrinkTowards: Alignment.Vertical = Alignment.Bottom,
    clip: Boolean = true,
    targetHeight: (fullHeight: Int) -> Int = { 0 },
) = androidx.compose.animation.shrinkVertically(animationSpec, shrinkTowards, clip, targetHeight)
